package com.tianyi.sfzy1.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tianyi.sfzy1.domain.Psychologicalquestion;
import com.tianyi.sfzy1.domain.Psychologyknowledge;
import com.tianyi.sfzy1.mapper.PsychologicalquestionMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PsychologicalquestionService {
    @Autowired
    PsychologicalquestionMapper psychologicalquestionMapper;

    public int add(Psychologicalquestion record){
        return psychologicalquestionMapper.insert(record);
    }
    public List<Psychologicalquestion> findAll(){
        return  psychologicalquestionMapper.selectAll();

    }
//    删除
    public int delete(Long id){
        return  psychologicalquestionMapper.deleteByPrimaryKey(id);
    }
//    部分添加
    public int insertSelective(Psychologicalquestion record){
        return psychologicalquestionMapper.insertSelective(record);
    }
//    部分修改
    public  int updateByPrimaryKeySelective(Psychologicalquestion record){
        return psychologicalquestionMapper.updateByPrimaryKeySelective(record);
    }
//    删除多个
    public int deleteMany(List<Integer> ids){
        return psychologicalquestionMapper.deleteArr(ids);
    }
//    分页查询
    public  PageInfo<Psychologicalquestion> fenyesearch(Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Psychologicalquestion> list =psychologicalquestionMapper.selectAll();
        PageInfo<Psychologicalquestion> pageInfo = new PageInfo<>(list);
        return pageInfo;

    }
//    模糊查询
    public List<Psychologicalquestion> mohusearch(Psychologicalquestion record){
        return psychologicalquestionMapper.selectByExample(record);
    }
    //    多表 返回带有用户名的问题
    public List<Psychologicalquestion> searchAndMemberAll(Psychologicalquestion record){
        return psychologicalquestionMapper.searchAllByMember(record);
    }
//    多表返回带有用户名分页
    public PageInfo<Psychologicalquestion> fenyesearchAndMember( Psychologicalquestion record, Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Psychologicalquestion> list =psychologicalquestionMapper.searchAllByMember(record);
        PageInfo<Psychologicalquestion> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


//       通过问题名或者问题内容或者关联会员表的会员用户名查询问题信息-->
//    孟迪
    public List<Psychologicalquestion> searchAllByMember1(@Param("questionTitle") String questionTitle, @Param("questionContent") String questionContent, @Param("memberName") String memberName){
        return psychologicalquestionMapper.searchAllByMember1(questionTitle,questionContent,memberName);
    }

}
